<?php

namespace app\common\service;
use app\common\service\AbstractService;
use app\systems\model\CommonExportCsvDownloadLogModel;
use app\systems\model\CommonExportCsvTaskLogModel;
use app\systems\model\CommonExportCsvCreateInfoModel;
use app\systems\logic\SystemMqLogic;
use app\systems\logic\MqTaskPushLogic;
use app\common\service\CommonExportCsvTaskLogService;
use think\facade\Request;

class CommonExportInfoDetailService extends AbstractService
{

    public $export_csv_create_info_model;
    const EXPORT_DETAIL_INIT = 0;
    const EXPORT_DETAIL_ING = 1;
    const EXPORT_DETAIL_SUCCESS = 2;
    const EXPORT_DETAIL_FAIL = 3;
    const EXPORT_DETAIL_CANCEL= 4;
    const EXPORT_MAP = [
        self::EXPORT_DETAIL_INIT => '初始化',
        self::EXPORT_DETAIL_ING => '进行中',
        self::EXPORT_DETAIL_SUCCESS => '成功',
        self::EXPORT_DETAIL_FAIL => '失败',
        self::EXPORT_DETAIL_CANCEL => '取消',
    ];



    /**
     * @Notes:生成导出CSV
     * @Author: TCP
     * @Date: 2021/03/26
     * @Time: 10:57
     * @param $param
     */
    public function createCsvInfo($message){
        set_time_limit(0);
        ini_set('memory_limit', '-1');
        $id   =  $message['id']??'';
        $info =  (new CommonExportCsvCreateInfoModel())->find(['id'=>$id]);
        $info =  objectToArray($info);
        if(!$info)   return true;
        if(!in_array($info['status'],[1,2,4])){
            (new CommonExportCsvCreateInfoModel())->where(['id'=>$id])->update(
                [
                    'status'     =>1,
                    'create_time'=>date('Y-m-d H:i:s')
                ]
            );
        }
        CommonExportCsvTaskLogService::staticModel()->composeCreateCsv($info['export_csv_task_id'],$info['task_done_no']);
        return true;

    }






}